import Vue from 'vue';
import Vuex from 'vuex';
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex);
const store = new Vuex.Store({
    state: {
        currentLoginUserStatus: null, //登录状态
        currentLoginUserInfo: JSON.parse(localStorage.getItem("currentLoginUserInfo")),
        currentActiveIndex: '/' //网站首页
    },
    mutations: {
        //同步去修改状态
        changeCurrentLoginUserStatus(state, value) {
            state.currentLoginUserStatus = value;
        },

        changeCurrentActiveIndex(state, value) {
            state.currentActiveIndex = value;
        }
    },
    plugins: [
        // veux持久化配置
        createPersistedState({
            //可以持久化到sessionStorage或者localStorage中。
            storage: window.sessionStorage,
            //storage: window.localStorage,
            //key: 'currentLoginUserStatus',
            render(state) {
                return {...state};
            }
        })
    ]
});
export default store;